package pojo;

import DataBase.SQL_Readin;
import InterFace.UTable_api;

import javax.swing.*;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

public class UTable implements UTable_api {//郭
    SQL_Readin db = new SQL_Readin();
    public JList<String> creat_table_peo(String type,String className){//郭
       if(type.equals("readPeople")){
          return new JList<>(read_table_peo(className));
       }
       else if(type.equals("readUnit")){
           return new JList<>(read_table_unit(className));
       }
       else if(type.equals("readDuty")){
           return new JList<>(read_table_duty(className));
       }
       else if(type.equals("readAction")){
           return new JList<>(read_table_action(className));
       }
       else if(type.equals("readRePun")){
           return new JList<>(read_table_rePun(className));
       }
       else if(type.equals("readRePun_findNum")){
           return new JList<>(read_table_rePun_findNum(className));
       }
       return null;
    }

     public Vector<String> read_table_rePun_findNum(String num) {
        try {
            String temp="暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无"+" , "+"暂无"+ " , "+"暂无";
            List<RewardPunishmentRecord> list = db.readRePun_findNum(num);
            Vector<String> vector = new Vector<>();
            if(list !=null) {
                for (RewardPunishmentRecord rePun : list) {
                    temp = rePun.getRecordId() + " , " + rePun.getNumber() + " , " + rePun.getName() + " , " + rePun.getRpType() + " , " + rePun.getReason() + " , " + rePun.getRpDate();
                    vector.add(temp);
                }
            }else vector.add(temp);
            return vector;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public Vector<String> read_table_rePun(String className) {//郭
        try {
            String temp="暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无"+" , "+"暂无"+ " , "+"暂无";
            List<RewardPunishmentRecord> list = db.readRePun(className);
            Vector<String> vector = new Vector<>();
            if(list !=null) {
                for (RewardPunishmentRecord rePun : list) {
                    temp = rePun.getRecordId() + " , " + rePun.getNumber() + " , " + rePun.getName() + " , " + rePun.getRpType() + " , " + rePun.getReason() + " , " + rePun.getRpDate();
                    vector.add(temp);
                }
            }else vector.add(temp);
            return vector;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public Vector<String> read_table_action(String calssName) {//郭
        try {
            String temp="暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无"+" , "+"暂无";
            List<ActivityRecord> list = db.getAllActivity(calssName);
            Vector<String> vector = new Vector<>();
            if (list != null) {
                for (ActivityRecord action : list) {
                    temp=action.getActivityId()+" , "+action.getClassName()+" , "+action.getActivityName()+" , "+action.getActivityDate()+" , "+action.getHost()+" , "+action.getLocation()+" , "+action.getParticipantsCount()+" , "+action.getActivityContent();
                    vector.add(temp);
                }
            }else vector.add(temp);
            return vector;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public Vector<String> read_table_peo(String className){//郭
        try {
            String temp="暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无";
            List<ClassMember> list = db.readPeople(className);
            Vector<String> vector = new Vector<>();
            if (list != null) {
                for (ClassMember classMember : list) {
                    temp=classMember.getNumber()+" , "+classMember.getClassId()+" , "+classMember.getName()+" , "+classMember.getSex()+" , "+classMember.getAge()+" , "+classMember.getContactInfo()+" , "+classMember.getDormitoryAddress();
                    vector.add(temp);
                }
            }else vector.add(temp);
            return vector;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    public  Vector<String> read_table_unit(String className){//郭
        try {
            String temp="暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无"+" , "+"暂无"+ " , "+"暂无";
            List<CommitteeMember> list = db.readUnit(className);
            Vector<String> vector = new Vector<>();
            if (list != null) {
                for (CommitteeMember committeeMember : list) {
                    temp=committeeMember.getNumber()+" , "+committeeMember.getClassName()+" , "+committeeMember.getStuName()+ " , " +committeeMember.getPosition()+" , "+committeeMember.getAppointmentDate()+" , "+committeeMember.getTermDuration();
                    vector.add(temp);
                }
            }else vector.add(temp);
            return vector;
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    }
    public Vector<String> read_table_duty(String className){//郭
        try {
            String temp="暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无"+" , "+"暂无";
            List<DutySchedule> list = db.readDuty(className);
            Vector<String> vector = new Vector<>();
            if (list != null) {
                for (DutySchedule dutySchedule : list) {
                    temp = dutySchedule.getNumber() + " , " + dutySchedule.getClassName() + " , " + dutySchedule.getStuName() + " , " + dutySchedule.getDutyDate() + " , " + dutySchedule.getTaskDescription();
                    vector.add(temp);
                }
            }else vector.add(temp);
            return vector;
        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }
    }
    public JList<String> creat_table_money(String type,String className){//王
        if(type.equals("readMoney")){
            return new JList<>(read_table_money(className));
        }
        return null;
    }
    Vector<String> read_table_money(String className){//王
        try {
            String temp="暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无"+" , "+"暂无"+ " , "+"暂无";
            List<ExpenseRecord> list = db.readMoney(className);
            Vector<String> vector = new Vector<>();
            if (list != null) {
                for (ExpenseRecord expenseRecord : list) {
                    temp = expenseRecord.getRecordId() + " , " + expenseRecord.getClassName() + " , " + expenseRecord.getExpenseType() + " , " + expenseRecord.getAmount() + " , " + expenseRecord.getExpenseDate() + " , " + expenseRecord.getRemarks();
                    vector.add(temp);
                }
            }else vector.add(temp);
            return vector;
        } catch (SQLException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    public JList<String> creat_table_message(String type, String className) {//郭
        if(type.equals("readMessage")){
            return new JList<>(read_table_message(className));
        }
        return null;
    }

    public Vector<String> read_table_message(String className) {//郭
        try {
            String temp="暂无"+" , "+"暂无"+ " , "+"暂无"+" , "+"暂无"+" , "+"暂无";
            List<MessageBoard> list = db.readMessage(className);
            Vector<String> vector = new Vector<>();
            if (list != null) {
                for (MessageBoard messageBoard : list) {
                        temp=messageBoard.getMessageId()+" , "+messageBoard.getClassName()+" , "+messageBoard.getStudentName()+" , "+messageBoard.getMessageContent()+" , "+messageBoard.getMessageDate();
                    vector.add(temp);
                }
            }else vector.add(temp);

            return vector;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}